﻿using GPSTracker.API.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GPSTracker.API.DAL
{
    public class MasterDAL
    {
        public static List<DataModel.SP_GetBranches_RESTResult> GetBranches(DataModel.ClientData cd)
        {
            try
            {
                var login = LoginDAL.CheckLoginByMobile(cd.LoginName, cd.LoginPwd, "GetBranches");

                if (login != null)
                {
                    var context = new DataModel.GpsDCDataContext(CommonFx.GetConStr());
                    return context.SP_GetBranches_REST().ToList();
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                var el = new DataModel.ErrorLog();
                el.ErrorMessage = ex.Message;
                el.ErrorForm = "MasterDAL";
                el.ErrorFunction = "GetBranches";
                CommonDAL.AddErrorLog(el);

                return null;
            }
        }

        public static List<DataModel.SP_GetWarehouse_RESTResult> GetWarehouse(DataModel.ClientData cd)
        {
            try
            {
                var login = LoginDAL.CheckLoginByMobile(cd.LoginName, cd.LoginPwd, "GetWarehouse");

                if (login != null)
                {
                    var context = new DataModel.GpsDCDataContext(CommonFx.GetConStr());
                    return context.SP_GetWarehouse_REST().ToList();
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                var el = new DataModel.ErrorLog();
                el.ErrorMessage = ex.Message;
                el.ErrorForm = "MasterDAL";
                el.ErrorFunction = "GetWarehouse";
                CommonDAL.AddErrorLog(el);

                return null;
            }
        }

        public static List<DataModel.SP_GetTempos_RESTResult> GetTempos(DataModel.ClientData cd)
        {
            try
            {
                var login = LoginDAL.CheckLoginByMobile(cd.LoginName, cd.LoginPwd, "GetTempos");

                if (login != null)
                {
                    var context = new DataModel.GpsDCDataContext(CommonFx.GetConStr());
                    return context.SP_GetTempos_REST().ToList();
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                var el = new DataModel.ErrorLog();
                el.ErrorMessage = ex.Message;
                el.ErrorForm = "MasterDAL";
                el.ErrorFunction = "GetTempos";
                CommonDAL.AddErrorLog(el);

                return null;
            }
        }
    }
}